package com.woniuxy.controller;

import com.woniuxy.entity.Lesson;
import com.woniuxy.entity.PageBean;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.LessonService;
import com.woniuxy.utils.CodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/lesson")
public class LessonController {

    @Autowired
    private LessonService lessonService;


    /**
     * 按条件分页查询该场馆的课程
     * @param lesson 课程条件
     * @param page 页码
     * @param pageSize 每页数目
     * @return ResponseEntity
     */
    @GetMapping("/condition/{page}/{pageSize}")
    public ResponseEntity<PageBean<Lesson>> findLessonsByCondition(@RequestBody Lesson lesson, @PathVariable("page") int page, @PathVariable("pageSize") int pageSize){
        ResponseEntity<PageBean<Lesson>> lessonBeanResponseEntity = new ResponseEntity<>();
        if (lesson==null){
            return lessonBeanResponseEntity.setCode(CodeUtils.ERROR_CODE).setMsg("查询失败");
        }
        //根据条件查询结果
        List<Lesson> results = lessonService.findLessonsByCondition(lesson, page, pageSize);
        PageBean<Lesson> lessonPageBean = new PageBean<>();
        lessonPageBean.setData(results);
        return lessonBeanResponseEntity.setCode(CodeUtils.SUCCESS_CODE)
                .setMsg("这是你要课程").setData(lessonPageBean);
    }

    /**
     * 获取当前场馆的所有的课程
     * @param vid 场馆id
     * @return 该场馆所有课程
     */
    @GetMapping("/allLessons/{vid}")
    public ResponseEntity<List<Lesson>> allLessons(@PathVariable("vid") int vid){
        ResponseEntity<List<Lesson>> lessonListResponseEntity = new ResponseEntity<>();
        System.out.println("课程：");
        System.out.println(vid);
        List<Lesson> allLessonsByVenueId = lessonService.findAllLessonsByVenueId(vid);
        if (allLessonsByVenueId!=null){
            return lessonListResponseEntity.setMsg("你的课程们").setCode(CodeUtils.SUCCESS_CODE).setData(allLessonsByVenueId);
        }
        return lessonListResponseEntity.setCode(CodeUtils.ERROR_CODE).setMsg("有问题");
    }
}
